package com.hmall.search.web;

import com.hmall.common.client.ItemApi;
import com.hmall.common.vo.PageVO;
import com.hmall.search.dto.SearchPageQueryDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.service.SearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/search")
public class SearchController {

    private final SearchService searchService;

    /**
     * 页面查询
     *
     * @param searchPageQueryDTO 搜索页面查询 DTO
     * @return {@link PageVO}<{@link ItemDoc}>
     */
    @PostMapping("/list")
    public PageVO<ItemDoc> pageQuery(@RequestBody SearchPageQueryDTO searchPageQueryDTO) {
        return searchService.pageQuery(searchPageQueryDTO);
    }

    /**
     * 建议
     *
     * @param key 钥匙
     * @return {@link List}<{@link String}>
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(String key) {
        return searchService.suggestion(key);
    }

    /**
     * 过滤 器
     *
     * @param searchPageQueryDTO 搜索页面查询 DTO
     * @return {@link Map}<{@link String}, {@link List}<{@link String}>>
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody SearchPageQueryDTO searchPageQueryDTO){
        return searchService.filters(searchPageQueryDTO);
    }


}
